<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>省份与城市互动</title>
</head>
<body>
    <div id="app">
        <p v-text="title"></p>
        <select v-on:change="selectCity($event)">
            <option value="">-</option>
            <option v-for="(item, index) in citys" v-bind:value="index+1">{{item}}</option>
        </select>
        <p>{{outProw}}<span v-show="isShow">省{{city}}, 欢迎您！</span></p>
    </div>
</body>
<script src="vue.js"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            title: "请选择",
            citys:['广州', '长沙', '武汉'],
            outProw: '',
            isShow: false
        },
        computed: {
            city: function() {
                if(this.outProw != "") {
                    switch(this.outProw){
                        case '广东':
                            return '广州';
                            break;
                        case '湖南':
                            return '长沙';
                            break;
                        case '湖北':
                            return '武汉';
                            break;
                        case '广西':
                            return '百色';
                            break;
                    }
                }else{
                    return '';
                }
            }
        },
        watch: {
            outProw: function() {
                if(this.outProw == "") {
                    this.isShow = false;
                }else{
                    return this.isShow = true;
                }
            }
        },
        methods: {
            selectCity: function(e) {
                console.log(e.target.value);

                let item = e.target.value;

                switch(item){
                    case '1':
                        return this.outProw = '广东';
                        break;
                    case '2':
                        return this.outProw = '湖南';
                        break;
                    case '3':
                        return this.outProw = '湖北';
                        break;
                    case '4':
                        return this.outProw = '广西';
                        break;
                    case '':
                        return this.outProw = '';
                        break;
                }
            }
        }
    })
</script>
</html>